package com.luych.toolbox.data.service.dao;

import com.luych.toolbox.common.enums.DataCompareHistoryStatus;
import com.luych.toolbox.data.service.entity.DataCompareHistory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.Date;
import java.util.List;

public interface DataCompareHistoryDao extends JpaRepository<DataCompareHistory, String>, JpaSpecificationExecutor<DataCompareHistory> {

    int countByDataSourceOneIdOrDataSourceTwoId(String dataSourceOneId, String dataSourceTwoId);

    int countByDataComparePlanId(String dataComparePlanId);

    Page<DataCompareHistory> findByNameLike(String name, Pageable pageable);

    List<DataCompareHistory> findByStatusIn(List<DataCompareHistoryStatus> status);

    @Modifying
    @Query(value = "TRUNCATE data_compare_history", nativeQuery = true)
    void truncate();

    long countByStartDateBetween(Date start, Date end);

    void deleteByIdIn(List<String> ids);

}